package io.renren.modules.member_score.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.modules.member.entity.V9MemberEntity;
import io.renren.modules.member.service.V9MemberService;
import io.renren.modules.member_score.dao.V9MemberScoreDao;
import io.renren.modules.member_score.entity.V9MemberScoreEntity;
import io.renren.modules.member_score.service.V9MemberScoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service("v9MemberScoreService")
public class V9MemberScoreServiceImpl extends ServiceImpl<V9MemberScoreDao, V9MemberScoreEntity> implements V9MemberScoreService {
    @Autowired
    private V9MemberScoreDao V9MemberScoreDao;
    @Autowired
    V9MemberService v9MemberService;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<V9MemberScoreEntity> page = this.page(
                new Query<V9MemberScoreEntity>().getPage(params,"id",true),
                new QueryWrapper<V9MemberScoreEntity>()
               /* Integer pages = Integer.parseInt(params.get("page").toString());
                Integer limit = Integer.parseInt(params.get("limit").toString());
                int page = (pages -1)*limit;
                params.put("page",page);
                params.put("limit",limit);
                List<V9MemberScoreVO> list = V9MemberScoreDao.selectMemberScore(params);
                int count = V9MemberScoreDao.selectMemberScoreCount(params);
                Page<V9MemberScoreVO> page1 = new Page<>(pages,limit);
                page1.setRecords(list);
                page1.setTotal(count);
                page1.setCurrent(pages);
                page1.setSize(limit);
                return new PageUtils(page1);*/
        );
        List<V9MemberScoreEntity> records = page.getRecords();
        for (int i = 0; i < records.size(); i++) {
            V9MemberEntity userEntiy = v9MemberService.getOne(new QueryWrapper<V9MemberEntity>().eq("userid", records.get(i).getUserid()));

            if (userEntiy !=null){

                String code=userEntiy.getUsername();
                records.get(i).setUsername(code);
            }


            if (userEntiy != null){
                String code=userEntiy.getUsername();
                records.get(i).setUsername(code);
            }

        }
        page.setRecords(records);

        return new PageUtils(page);

        /*List<V9MemberScoreEntity> records = page.getRecords();
        List<V9MemberScoreVO> list = new ArrayList<>();
        for (int i = 0; i < records.size(); i++) {
            V9MemberEntity userid = v9MemberService.getOne(new QueryWrapper<V9MemberEntity>().eq("userid", records.get(i).getUserid()));
            V9MemberScoreVO vo = new V9MemberScoreVO();
            vo.setUserid(userid.getUsername());
            BeanUtils.copyProperties(records.get(i),vo);
            list.add(vo);
        }
        int count = (int) page.getTotal();
        int size = (int) page.getSize();
        int curr = (int) page.getCurrent();


        return new PageUtils(list,count,size,curr);*/
    }

}
